package com.starblink.library.widget.loading

import android.content.Context
import android.graphics.Color
import android.util.AttributeSet
import android.view.View
import android.view.ViewGroup
import androidx.constraintlayout.widget.ConstraintLayout
import com.starblink.android.basic.ext.enableCorner
import com.starblink.android.basic.ext.inflater
import com.starblink.android.basic.extension.dp2px
import com.starblink.library.widget.databinding.VGoodsCardLoadingBinding

/**
 * 商品卡片加载过渡View
 * Create by yuanl at 2023/03/28
 */
class GoodsCardLoadingView @JvmOverloads constructor(
    context: Context,
    attr: AttributeSet? = null,
    themeId: Int = 0
) : ConstraintLayout(context, attr, themeId) {

    private val binding = VGoodsCardLoadingBinding.inflate(inflater, this)

    init {
        setBackgroundResource(com.starblink.basic.style.R.color.sk_gray0)
        enableCorner(16.dp2px())
        binding.vShm1.enableCorner(4.dp2px())
        binding.vShm2.enableCorner(4.dp2px())
        binding.vShm3.enableCorner(4.dp2px())

    }

    override fun onAttachedToWindow() {
        super.onAttachedToWindow()
        /*binding.vShm1.startShimmerAnimation()
        binding.vShm2.startShimmerAnimation()
        binding.vShm3.startShimmerAnimation()*/
    }

    override fun onDetachedFromWindow() {
        binding.vShm1.stopShimmerAnimation()
        binding.vShm2.stopShimmerAnimation()
        binding.vShm3.stopShimmerAnimation()
        super.onDetachedFromWindow()
    }

    override fun attachViewToParent(child: View?, index: Int, params: ViewGroup.LayoutParams?) {
        super.attachViewToParent(child, index, params)

    }

    override fun detachViewFromParent(child: View?) {
        super.detachViewFromParent(child)
    }


}